package com.neusoft.service.impl;

import com.neusoft.entity.ArticlesEntity;
import com.neusoft.entity.UsersEntity;
import com.neusoft.exception.MyException;
import com.neusoft.mapper.ArticleMapper;
import com.neusoft.mapper.UsersMapper;
import com.neusoft.service.IArticleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.UUID;

@Service
public class ArticleService implements IArticleService {
    @Resource
    ArticleMapper articleMapper;
    @Resource
    UsersMapper usersMapper;
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void processArticle() {
//        if(usersEntity != null){
//            throw new MyException("xxxxx");
//        }
        try{
            UsersEntity usersEntity = new UsersEntity();
            usersEntity.setUsername("abc");
            usersMapper.insert(usersEntity);
            int k = 90/0;
            ArticlesEntity articlesEntity = new ArticlesEntity();
            articlesEntity.setSlug(UUID.randomUUID().toString());
            articlesEntity.setUserId(usersEntity.getId());
            articleMapper.insert(articlesEntity);
        }
        catch (Exception exception){
            System.out.println(exception.getMessage());
        }


    }
}
